#选取基础镜像
FROM ubuntu:20.04

#更换apt源并更新
RUN sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' /etc/apt/sources.list && apt update

#安装SSH服务并生成主机密钥
RUN apt-get update -y && \
    apt-get install -y --no-install-recommends openssh-server openssl && \
    mkdir -p /var/run/sshd && \
    ssh-keygen -A && \
    rm -rf /var/lib/apt/lists/*

#修改root用户密码
RUN echo "root:Secure@123#Pass" | chpasswd && \
    sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config

#声明开放端口
EXPOSE 22

#设置SSH前台服务为启动命令
CMD ["/usr/sbin/sshd", "-D"]